
import 'package:mvvmdemo/common/appglabaldata.dart';
import 'package:mvvmdemo/service/netservice.dart';
import 'package:mvvmdemo/utils/timeutils.dart';

class ParameterInterface {

  static ParameterInterface? _instance;
  static ParameterInterface? getNetService() {
    _instance??= ParameterInterface();
    return _instance;
  }
  Future<dynamic> posStartupCertify({erpCode, mkt, syjh, ipAdress, version,}) async{

    Map<String, dynamic> data = {
      'command_id': 'INITCERTIFY',
      'erpCode': erpCode,
      'mkt': mkt,
      'syjh': syjh,
      'ipAddress': ipAdress,
      'version': version,
      'offlineMode':0
    };
   return await NetService.getNetService()!.requestHttp("系统初始化", data);
  }

  //2.登录
  Future<dynamic> posLogin (
      {
      cardno,
      gh,
      passwd,
      mkt,
      syjh,
      erpCode,
      loginFlag,
      workRound,
      empLoginType,
      entId,
      bool isLocalUrl = false,
      netType
      }) async{

    Map<String, dynamic> data = {
      'command_id': 'LOGINCERTIFY',
      'cardno': cardno,
      'gh': gh, //工号
      'passwd': passwd, //密码
      'mkt': mkt, //门店号
      'syjh': syjh, //收银机号
      'erpCode': erpCode, //
      'loginFlag': loginFlag, //
      'workRound': '0', //
      'empLoginType': empLoginType, //0-收银员登陆 1-扫描员登陆
      'entId':entId,
      'netType': netType
    };
    return await NetService.getNetService()!.requestHttp("登录", data);
  }

  Future<Map> tradeInit(
      {scanGoodOperator,
        shopCode,
        terminalNo,
        terminalOperator,
        saleDate,
        erpCode,
        orderType,
        shopName,
        shopID,
        scheduleCode,
        language,
        entId,
        precisionMode,
        flag,
        popMode,
        accreditNo,
        reason,
        reasonId,
        posType,
        stallCode,
        maxSaleGoodsQuantity,
        maxSaleGoodsMoney,
        maxSaleMoney,
        terminalSno,
        channel}) async{
    Map<String, dynamic> data = {
      'command_id': 'POSCERTIFY', //命令号
      'scanGoodOperator': "7005", //扫描员工号
      'terminalSno': "0000331",
      'shopCode': "80001", //门店号
      'terminalNo': "0001", //终端号(收银机号)
      'terminalOperator': "7005", //操作员号（收银员号）
      'saleDate': TimeUtils.getDate(), //日期时间
      'erpCode': "004", //经营公司
      'orderType': "1",//orderType==SellType.groupBuying?SellType.sale:orderType, //单据类型
      'shopName': "芮欧百货", //门店名称
      'shopID': '0', //shopID, //门店ID
      'scheduleCode': "0",//'1', //班次
      'language': 'CHN', //小票语言
      'entId': 0, //企业ID
      'precisionMode':"0", //整单四舍五入方式
      'flag': "0", //备用默认0
      'popMode': "1", //促销模式 默认1
      'accreditNo': accreditNo, //授权卡号
      'reason': reason, //退货原因
      'reasonId': reasonId, //退货原因ID
      'posType': '0', //终端类型默认0
      'stallCode': stallCode, //档口编码
      'maxSaleGoodsQuantity': "1000", //最大商品数量默认200
      'maxSaleGoodsMoney': "999999999", //最大商品单价默认99999999
      'maxSaleMoney': "999999999", //整单最大成交金额默认99999999
      'channel':  "javapos", //销售渠道
    };

    return await NetService.getNetService()!.requestHttp("交易初始化", data);

  }

  Future<dynamic> findGoods1(
      {shopCode,
        terminalNo,
        terminalOperator,
        flowNo,
        erpCode,
        barNo,
        calcMode,
        flag,
        precision,
        isdzcm,
        searchType,
        assistantId,
        refPrice,
        scanCode,
        orgCode,
        weight,
        remark
      }) async {
    Map<String, dynamic> data = {
      "command_id": "FINDGOODSTIFY", //命令号
      "shopCode": "80001", //门店号
      "terminalNo": "0001", //终端号(收银机号)
      "terminalOperator": "7005", //操作员号（收银员号）
      "flowNo": AppGlabalData.flowNo, //交易流水号（缓存唯一号）
      "erpCode": "004", //经营公司
      "barNo": "000221", //商品条码
      "calcMode": "0", //营业员号
      "flag": "0",
      "precision": "2",
      "isdzcm": "N", //是否电子称码
      "searchType": "3", //查找类型 1-不控制专柜  2-控制专柜
      "assistantId": "", //营业员
      "orgCode" : "", //营业员柜组
      "refPrice": "", //商品售价
      "scanCode": "",
      "qty": "0",
      "remark": ""
    };

    return await NetService.getNetService()!.requestHttp("查找商品", data);
  }

  Future<dynamic> findGoods2(
      {shopCode,
        terminalNo,
        terminalOperator,
        flowNo,
        erpCode,
        barNo,
        calcMode,
        flag,
        precision,
        isdzcm,
        searchType,
        assistantId,
        refPrice,
        scanCode,
        orgCode,
        weight,
        remark
      }) async {
    Map<String, dynamic> data = {
      "command_id": "FINDGOODSTIFY", //命令号
      "shopCode": "80001", //门店号
      "terminalNo": "0001", //终端号(收银机号)
      "terminalOperator": "7005", //操作员号（收银员号）
      "flowNo": AppGlabalData.flowNo, //交易流水号（缓存唯一号）
      "erpCode": "004", //经营公司
      "barNo": "000227", //商品条码
      "calcMode": "0", //营业员号
      "flag": "0",
      "precision": "2",
      "isdzcm": "N", //是否电子称码
      "searchType": "3", //查找类型 1-不控制专柜  2-控制专柜
      "assistantId": "", //营业员
      "orgCode" : "", //营业员柜组
      "refPrice": "", //商品售价
      "scanCode": "",
      "qty": "0",
      "remark": ""
    };

    return await NetService.getNetService()!.requestHttp("查找商品", data);
  }

}
